<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="util.Constant, db.DBMain, db.tables.DBUserNameTable,
			java.util.ArrayList" %>

<%  if(request.getParameter("suchen") != null) {
		String nametofind = request.getParameter(Constant.USER_NAME);
		String[] columns = {DBUserNameTable.USER_NAME_COL, DBUserNameTable.USER_ID_COL};
		String[] cols = {DBUserNameTable.USER_NAME_COL};
		Object[] keys = {nametofind};
		ArrayList<ArrayList<Object>> result = DBMain.getUserNameTable().getSearchSelect(columns, cols, keys);
		if(result!=null){
			%>
			<h1>Ergebnisse ihrer Suche:</h1>
			<ul>
			<% for(int i=1;i<result.size();i++){
			  ArrayList<Object> tmp = result.get(i); 
			  String name = (String)tmp.get(0);
			  Long user_id = (Long)tmp.get(1);%>
				  <li>
			 	<%= name %>
			 	<% if(DBMain.getContactTable().
			 			areUserFriends((Long)session.getAttribute(
			 					Constant.USERID), user_id)) { %>
			 	<form name="profil" method="post" 
				action="./index.jsp?<%=Constant.CONTENT%>=<%=Constant.profile %>&targedid=<%=user_id%>">
				<input type="submit" name="profilbetrachten" value="Profil des Freundes betrachten">		
				</form>
				<% } else { %>
				<form name="addfriend" method="post" 
				action="./index.jsp?<%=Constant.CONTENT%>=<%=Constant.add_friend %>&<%=Constant.TARGET%>=<%=user_id%>">
		    	<input type="submit" name="freundadden" value="Zur Freundesliste hinzufuegen">		
		    	</form>
				<%} %>
				<form name="nachricht" method="post" 
				action="./index.jsp?<%=Constant.CONTENT%>=<%=Constant.message %>&<%=Constant.TARGET%>=<%=user_id%>">
    			<input type="submit" name="nachrichtschicken" value="Nachricht senden">		
    			</form>
				</li>
				<%	} %>
			</ul>
<% 		}
	
}%>
<p align="center"><b>Suche nach Personen:</b></p>
  <form name="form1" method="post" action="./index.jsp?<%=Constant.CONTENT%>=<%=Constant.search%>">
    <p align="center">Name:
	<input type="text" name="<%= Constant.USER_NAME %>" value="" size="30">
    </p>
  <p align="center"> 
    <input type="submit" name="suchen" value="Suchen">
    <input type="reset" name="Zur&uuml;cksetzen" value="Zur&uuml;cksetzen">
  </p>
  </form>